<template>
  <div class="container">
    <el-dialog title="机构查询" :visible.sync="organizatioDialog.centerDialogVisible" width="700px" center :lock-scroll="true"
      @close="cancel" @open="getSelect">
      <div class="top">
        <el-select v-model="search.select" @change="clickSeelct">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-input style="width:200px;margin:0 10px" v-model="search.value" placeholder="请输入内容"></el-input>
        <el-button size="small" type="primary" icon="el-icon-search" class="handleSearch"
          @click="handleSearch()">查询</el-button>
      </div>
      <el-table :data="formData" max-height="450px" border style="width: 100%;margin-top:10px" ref="multipleTable"
        @selection-change="handleSelectionChange" empty-text="暂无数据">
        <el-table-column type="selection" width="50" align="center"></el-table-column>
        <el-table-column prop="erp_org_code" label="机构编码" align="center"></el-table-column>
        <el-table-column prop="name" label="机构名称" align="center"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// import { selectOrgData} from "@/api/superOrder/superOrderList";
import { getOrgData } from "@/api/middleorder/middleorderlist";
export default {
  props: {
    organizatioDialog: Object
  },
  data() {
    return {
      formData: null,
      options: [],
      search: {
        select: "",
        value: ""
      },
      tags: []
    };
  },
  methods: {
    handleSearch() {
      this.formData = [];
      this.getData();
    },
    getSelect() {
      this.options = [
        {
          value: "",
          label: "机构名称"
        },
        {
          value: "1",
          label: "机构编码"
        }
      ];
    },
    getData() {
      let data = {};
      switch (this.search.select) {
        case "":
          data = {
            key: this.search.value,
            limit: 1000
          };
          break;
        case "1":
          data = {

            key: this.search.value,
            limit: 1000
          };
          break;

      }
      getOrgData(data).then(res => {
        if (res.code == 0) {
          if (this.organizatioDialog.type) {
          
            this.formData = res.data;
            this.formData.unshift({
              erp_org_code: '0',
              name: '中仓'
            })
          } else {
            this.formData = res.data;

          }
        }
      });
    },
    clickSeelct() {
      this.search.value = "";
    },
    //确定
    confirm() {
      this.$emit("tag", this.tags);
      this.cancel();
    },
    //取消
    cancel() {
      this.search.value = '';
      this.formData = [];
      this.$refs.multipleTable.clearSelection();
      this.organizatioDialog.centerDialogVisible = false;
    },
    //选取
    handleSelectionChange(data) {
      this.tags = [];
      data.forEach(res => {
        this.tags.push({
          name: res.name,
          code: res.erp_org_code
        });
      });
    }
  }
};
</script>
<style scoped>
.top {
  display: flex;
  /* justify-content: center; */
}
</style>